package me.youline.dataServer.dao.authentication;

import me.youline.dataServer.entity.UserCredentialInfo;

import org.perf4j.aop.Profiled;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * 用户身份凭证数据操作对象
 * @author linhan
 */
@Repository
public interface UserCredentialInfoDAO extends
		JpaRepository<UserCredentialInfo, Long> {

	/**
	 * 根据用户名获取用户凭证
	 * 
	 * @param userName
	 * @return
	 */
	@Profiled(tag = "dao-根据用户名获取用户凭证")
	public UserCredentialInfo findByUserName(String userName);

	/**
	 * 根据userID查询用户凭证
	 * @param userId
	 * @return
	 */
	@Profiled(tag = "dao-根据userID查询用户凭证")
	public UserCredentialInfo findByUserId(Long userId);

	/**
	 * 指定的用户名是否已经存在
	 * @param userName
	 * @return
	 */
	@Query("select case when count(a) > 0 then true else false end from UserCredentialInfo a where a.userName = ?1")
	@Profiled(tag = "dao-指定的用户名是否已经存在")
	public boolean isExistUserName(String userName);
}
